
import axios from 'axios'
export default {
  data () {
    return {
      fileName: ''
    }
  },
  methods: {
    getBlobExport (params, url) {
      return axios({
        url: `${url}`,
        params,
        responseType: 'blob'
      })
    },
    async downLoadEnclosure (fileUrl) {
      let res = await this.getBlobExport({ fileUrl }, 'upload/downLoad')
      this.downloadFile(res)
    },
    downloadFile (blob) {
      if (!blob || !blob.data) {
        return
      }
      let _blob = new Blob([blob.data])
      let url = window.URL.createObjectURL(_blob)
      let link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.setAttribute('download', this.fileName || '下载.png')
      document.body.appendChild(link)
      link.click()
      setTimeout(() => {
        document.body.removeChild(link)
      }, 20000)
    }
  }
}
